$(document).ready( function(){
	$("body").on("click",".compareButton",  function(){
		var dataString = "get_compare_list=1";
		$("#ajaxLoader").show();
		$.ajax({
			type:'POST',
			url: scriptsURL+"libs/ajax/ajax-includes.php",
			data: dataString,
			success: function(response)
			{
				$("#messageDialog .modal-body").html(response);
				$('#messageDialog').modal('show');
				$("#ajaxLoader").hide();
			}
			});
	});
	
	
	$("body").on("click", ".addToCompare", function(){
		if($(this).attr("product_id"))
		{
			var element = $(this);
			var productID = $(this).attr("product_id");
			
			var dataString = "&add_to_compare="+productID;
			
			$("#ajaxLoader").show();
			$.ajax({
					type:'POST',
					url: scriptsURL+"libs/ajax/ajax-includes.php",
					data: dataString,
					success: function(responseJSON)
					{
						response = JSON.parse(responseJSON);
						
						var message = "";
						
						if(response.success)
						{
							message += '<div class="alert alert-success">'+response.success+'</div>';
						}
						else if(response.error)
						{
							message += '<div class="alert alert-danger">'+response.error+'</div>';
						}
						
						$("#ajaxLoader").hide();
						$("#messageDialog .modal-body").html(message);
						$('#messageDialog').modal('show');
						
						if(response.action)
						{
							var comparedProducts = 0;
							
							if(response.compared_products)
							{
								comparedProducts = response.compared_products; 
							}
							
							$(".comparedProducts span").html(response.compared_products);
							
							if(response.action == "delete")
							{
								element.removeClass("btn-danger");
							}
							else if(message.action = "add")
							{
								element.addClass("btn-danger");
							}
						}
					}
			});
			return false;
			
		}
	});
	
});
